figure.Bomb = new Class({
    Extends: figure.DomFigure,

    initialize: function(id, css) {
        this.parent(id);
        this.createElement('canvas', {
            id: id,
            Width: 25,
            Height: 25,
            class: 'bomba',
            css: css
        });
        this.element = this.getElement();
        this.radius = 8;
        this.color = 'blue';
        this.status = 'off';
        var me = this;
        this.element.on('prenderBomba', function prenderBomba(){
            me.turnOn();
        });
        this.element.on('apagarBomba', function apagarBomba(){
            me.turnOff();
        });
        this.element.on('romperBomba', function romperBomba(){
            me.break();
        })
    },

    draw: function() {
        var context = this.element[0].getContext('2d');
        context.beginPath();
        context.fillStyle = this._createGradient(context);
        context.arc(this.radius+1, this.radius +1 , this.radius, 0, 2*Math.PI, true);
        context.fill();
        context.stroke();
        context.fillRect(0,this.radius*2,18,2);
    },

    _createGradient: function(context) {
        var grd = context.createLinearGradient(5,0,10,10);
        grd.addColorStop(0,"white");
        grd.addColorStop(1, this.color);
        return grd;
    },


    turnOn: function() {
        if (this.color != 'green') {
            this.color = 'green';
            this.status = 'working';
            this.draw();
        }
    },

    getMessage: function() {
        var msg = this.parent();
        msg += 'status: ' + this.status;
        return msg;
    },

    turnOff: function() {
        if (this.color == 'green') {
            this.color = 'blue';
            this.status = 'off';
            this.draw();
        }
    },
    break: function() {
        this.color = 'red';
        this.status = 'broken';
        this.draw();
        $("#alarmaGeneral").trigger('encenderGral');
        $("#alarmaGeneral2").trigger('encenderGral');
        $("#alarmaGeneral3").trigger('encenderGral');
        window.alert('Error fatal, se rompio una bomba');
        figure.stopAnimation = true;
    }
});